package com.jozen.modelbase.netwoek.base;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;

import androidx.annotation.NonNull;


import com.jozen.modelbase.R;
import com.jozen.modelbase.netwoek.util.AppUtil;
import com.trello.rxlifecycle2.LifecycleTransformer;

/**
 * dialog 基类
 */
public class BaseDialog extends Dialog implements View.OnClickListener, BaseContract.BaseView {
    public Activity activity;

    public BaseDialog(@NonNull Activity activity) {
        super(activity, R.style.dialog_bg_theme);
        this.activity = activity;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        init(savedInstanceState);
    }

    protected int getLayoutId() {
        return 0;
    }

    protected void init(Bundle savedInstanceState) {

    }

    protected <T extends View> T findView(int pResId) {
        return (T) findViewById(pResId);
    }

    protected void findOnClick(int id) {
        findViewById(id).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                View view = getCurrentFocus();
                AppUtil.hideKeyboard(ev, view, activity);//调用方法判断是否需要隐藏键盘
                break;
            default:
                break;
        }
        return super.dispatchTouchEvent(ev);
    }

    @Override
    public void showSuccess(String message) {

    }

    @Override
    public void showFailed(String message) {

    }

    @Override
    public void showNoNet() {

    }

    @Override
    public void onRetry() {

    }

//    @Override
//    public void show() {
////        getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
////                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
////        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
//
//        super.show();
//    }

    @Override
    public <T> LifecycleTransformer<T> bindToLife() {
        return null;
    }
}
